home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 424_01 / ed_157 / move_line.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-11  |  2.3 KB  |  96 lines

  1. /*
  2.  * Copyright (C) 1992 by Rush Record (rhr@clio.rice.edu)
  3.  * 
  4.  * This file is part of ED.
  5.  * 
  6.  * ED is free software; you can redistribute it and/or modify it under the terms
  7.  * of the GNU General Public License as published by the Free Software Foundation.
  8.  * 
  9.  * ED is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  10.  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  11.  * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  12.  * 
  13.  * You should have received a copy of the GNU General Public License along with ED
  14.  * (see the file COPYING).  If not, write to the Free Software Foundation, 675
  15.  * Mass Ave, Cambridge, MA 02139, USA.
  16.  */
  17. #include "opsys.h"
  18.  
  19. #include "rec.h"
  20. #include "window.h"
  21. #include "ed_dec.h"
  22.  
  23. /******************************************************************************\
  24. |Routine: move_line
  25. |Callby: edit
  26. |Purpose: Moves the cursor to the beginnings of lines.
  27. |Arguments:
  28. |    repeat is the number of lines to move the cursor.
  29. \******************************************************************************/
  30. void move_line(repeat)
  31. register Int repeat;
  32. {
  33.     WANTCOL = 1;
  34.     if(DIRECTION < 0)
  35.     {
  36.         backspace(1);
  37.         if(--repeat)
  38.             up_arrow(repeat);
  39.     }
  40.     else
  41.         down_arrow(repeat);
  42. }
  43.  
  44. /******************************************************************************\
  45. |Routine: find_line
  46. |Callby: edit
  47. |Purpose: Does what move_line does, but instead of actually moving the cursor,
  48. |         returns an offset to the position at which the cursor would be.
  49. |Arguments:
  50. |    prepeat is the number of lines to (figuratively) move.
  51. \******************************************************************************/
  52. Int find_line(prepeat)
  53. Int prepeat;
  54. {
  55.     register Int repeat,curbyt;
  56.     Int offset;
  57.     rec_ptr currec;
  58.  
  59.     curbyt = CURBYT;
  60.     currec = CURREC;
  61.     offset = 0;
  62.     if(prepeat > 0)
  63.     {
  64.         repeat = prepeat;
  65.         while(repeat-- > 0)
  66.         {
  67.             if(currec == BASE)
  68.                 return(0);
  69.             offset += currec->length + 1 - curbyt;
  70.             curbyt = 0;
  71.             currec = currec->next;
  72.         }
  73.     }
  74.     else    /* backwards */
  75.     {
  76.         repeat = -prepeat;
  77.         while(repeat-- > 0)
  78.         {
  79.             if(currec->prev == BASE && !curbyt)
  80.                 return(0);
  81.             if(curbyt > 0)
  82.             {
  83.                 offset -= curbyt;
  84.                 curbyt = 0;
  85.             }
  86.             else
  87.             {
  88.                 currec = currec->prev;
  89.                 offset -= currec->length + 1;
  90.             }
  91.         }
  92.     }
  93.     return(offset);
  94. }
  95.  
  96.